package com.itheima.demo5;

import java.util.concurrent.CountDownLatch;

public class MyCountDownLatchDemo {
    public static void main(String[] args) {
        CountDownLatch countDownLatch = new CountDownLatch(3);

        new Thread(()->{
            for (int i = 1; i < 15; i++) {
                System.out.println(Thread.currentThread().getName()+"吃了"+i+"饺子");
            }
            countDownLatch.countDown();
        },"小明").start();

        new Thread(()->{
            for (int i = 1; i < 20; i++) {
                System.out.println(Thread.currentThread().getName()+"吃了"+i+"饺子");
            }
            countDownLatch.countDown();
        },"小花").start();

        new Thread(()->{
            for (int i = 1; i < 30; i++) {
                System.out.println(Thread.currentThread().getName()+"吃了"+i+"饺子");
            }
            countDownLatch.countDown();
        },"小民").start();

        new Thread(()->{
            try {
                countDownLatch.await();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            System.out.println(Thread.currentThread().getName()+"收拾碗筷");
        },"妈妈").start();
    }
}
